package com.yxr.mobileplayer.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.ImageView;

import com.yxr.mobileplayer.R;

/**
 * @Classname BatteryReceiver
 * @Description TODO
 * @Date 2020/2/26 11:55
 * @Created by yxr
 * @auth panda
 */
public class BatteryReceiver extends BroadcastReceiver {

    private ImageView iv_battery;

    public BatteryReceiver(ImageView iv_battery) {
        this.iv_battery = iv_battery;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        //主线程执行
        int level = intent.getIntExtra("level",0);//电量：0~100
        if(level<=0){
            iv_battery.setImageResource(R.drawable.ic_battery_0);
        }else if(level <=10){
            iv_battery.setImageResource(R.drawable.ic_battery_10);
        }else if(level <=20){
            iv_battery.setImageResource(R.drawable.ic_battery_20);
        }else if(level <=40){
            iv_battery.setImageResource(R.drawable.ic_battery_40);
        }else if(level <=60){
            iv_battery.setImageResource(R.drawable.ic_battery_60);
        }else if(level <=80){
            iv_battery.setImageResource(R.drawable.ic_battery_80);
        }else if(level <=100){
            iv_battery.setImageResource(R.drawable.ic_battery_100);
        }else{
            iv_battery.setImageResource(R.drawable.ic_battery_100);
        }
    }

}
